﻿package frEngine.loaders.particleSub.particleInstance
{

    public class OneParticleInstance extends Object
    {
        public var mesh:Object;
        public var callBack:Function;
        public var hasInitOk:Boolean = false;
        public static const Plane:int = 0;
        public static const CrossPlane:int = 1;
        public static const Box:int = 2;
        public static const Mesh:int = 3;

        public function OneParticleInstance()
        {
            return;
        }// end function

        public function init(param1:int, param2:Array) : void
        {
            switch(param1)
            {
                case Plane:
                {
                    this.mesh = new PlaneParticle(param2[0], param2[1], param2[2]);
                    this.initSurface();
                    break;
                }
                case CrossPlane:
                {
                    this.mesh = new CrossPlaneParticle(param2[0], param2[1], param2[2], param2[3]);
                    this.initSurface();
                    break;
                }
                case Box:
                {
                    this.mesh = new BoxParticle(param2[0], param2[1], param2[2]);
                    this.initSurface();
                    break;
                }
                case Mesh:
                {
                    this.mesh = new MeshParticle(param2[0], this.initSurface);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dispose() : void
        {
            this.mesh.dispose();
            this.mesh = null;
            this.callBack = null;
            return;
        }// end function

        private function initSurface() : void
        {
            this.hasInitOk = true;
            if (this.callBack != null)
            {
                this.callBack.apply();
                this.callBack = null;
            }
            return;
        }// end function

    }
}
